﻿using DBLayer;
using ModelLayer;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/// <summary>
/// Controller to control airports and route between them 
/// </summary>
namespace CtrLayer
{
    public class AirlineCtr
    {
        //Variables initialization
        private AirportDB airportDB;
        private FlightDB flightDB;

        //constructor
        public AirlineCtr()
        {
            airportDB = new AirportDB();
            flightDB = new FlightDB();
        }
        #region Airport
        //Insert Aiport into database
        public int InsertAirport(Airport _airport)
        {
            return airportDB.InsertAirport(_airport);
        }
        //Find and return airport by airportCode (string)
        public Airport FindAirportByCode(string _airportCode)
        {
            return airportDB.FindAirportByCode(_airportCode);
        }
        //Find and return airport by airportName (string)
        public Airport FindAirportByName(string _airportName)
        {
            return airportDB.FindAirportByName(_airportName);
        }
        //Update Airport by obj
        public int UpdateAirport(Airport _airport)
        {
            return airportDB.UpdateAirport(_airport);
        }
        //select all airports
        public List<Airport> SelectAllAirports()
        {
            return airportDB.SelectAll();
        }
        //remove airport by obj
        public int RemoveAirport(Airport _airport)
        {
            return airportDB.RemoveAirport(_airport);
        }
        //Check if 2 airport are connection by fights
        public bool HasConnection(Airport _departure, Airport _arrival)
        {
            return airportDB.HasConnection(_departure, _arrival);
        }
        //get possible airport by first airport
        public List<Airport> PossibleAirports(Airport _airport)
        {
            return airportDB.PossibleAirports(_airport);
        }
        #endregion
        #region Flight
        //Insert Flight into database
        public int InsertFlight(Flight _flight)
        {
            return flightDB.InsertFlight(_flight);
        }
        //find flight by airport
        public List<Flight> FindFlightByAirport(string _airportCode)
        {
            return flightDB.FindFlightByAirport(_airportCode);
        }
        //Find and return Flight by routeId (string)
        public Flight FindFlightByID(int _routeId)
        {
            return flightDB.FindFlightByID(_routeId);
        }
        //Update Flight by obj
        public int UpdateFlight(Flight _flight)
        {
            return flightDB.UpdateFlight(_flight);
        }
        //return all flight
        public List<Flight> SelectAllFlights()
        {
            return flightDB.SelectAll();
        }
        //RemoveFlight in database
        public int RemoveFlight(Flight _flight)
        {
            return flightDB.RemoveFlight(_flight);
        }
        //return a Flight between two airports
        public Flight FindFlightByAirports(Airport _startAirport, Airport _endAirport)
        {
            return flightDB.FindFlightByAirports(_startAirport, _endAirport);
        }
        #endregion

    }
}
